//
//  MarkV.swift
//  SearchHeader
//
//  Created by 万孟超 on 2023/10/16.
//

import Foundation
import AppKit
import SnapKit

class Mark: NSView {
    lazy var descripeLabel: NSTextField = {
       let tf = NSTextField()
        tf.isVerticalCenter = true
        tf.isBordered = false
        tf.font = .systemFont(ofSize: 15)
        tf.isEditable = false
        tf.textColor = .black
        tf.bezelStyle = .roundedBezel
        return tf
    }()
    
    lazy var descripeImageView: NSImageView = {
        let imageV = NSImageView()
        imageV.autoresizingMask = .height
        imageV.imageScaling = .scaleProportionallyUpOrDown
        return imageV
    }()
    
    init(title: String, imageName: String) {
        super.init(frame: .zero)
        descripeLabel.stringValue = title
        descripeImageView.image = NSImage(named: imageName)
        installView()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func installView() {
        addSubview(descripeLabel)
        descripeLabel.snp.makeConstraints { make in
            make.left.equalTo(10)
            make.top.equalTo(20)
        }
        
        addSubview(descripeImageView)
        let size = descripeImageView.image!.size
        descripeImageView.snp.makeConstraints { make in
            make.left.equalTo(20)
            make.right.equalTo(-20)
            make.top.equalTo(descripeLabel.snp.bottom).offset(20)
            make.bottom.equalTo(-10)
            make.width.equalTo(descripeImageView.snp.height).multipliedBy(size.width / size.height)
        }
    }
}

class MarkV: NSScrollView {
    
    let desStrings: [String] = ["1.点击Path按钮，选择目录",
                                "2.选择工程目录，点open确认选择",
                                "3.选择完路径后，自动生成Pods列表，",
                                "4.选择需要忽略的Pods库",
                                "5.点击搜索，查找项目中不规范的头文件引用",
                                "6.点击导出，导出搜索结果",
                                "7.点击图表查看，通过Excel查看详情"]
    
    init() {
        super.init(frame: .zero)
        drawsBackground = false
        installSubview()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func installSubview() {
        let content = NSView()
        var lastView: NSView?
        for idx in 1...7 {
            let view = Mark(title: desStrings[idx - 1], imageName: "\(idx)")
            content.addSubview(view)
            view.snp.makeConstraints { make in
                make.left.right.equalToSuperview()
                if let lastView = lastView {
                    make.top.equalTo(lastView.snp.bottom)
                }else{
                    make.top.equalToSuperview()
                }
                if idx == 7 {
                    make.bottom.equalToSuperview()
                }
            }
            lastView = view
        }
        documentView = content
        content.snp.makeConstraints { make in
            make.width.equalTo(850)
        }
        scrollToTop()
    }
}
